#include <malloc.h>
#include <stdio.h>
#include "list.h"


void Push( LinkList* pList, int nData )
{
	Node* pNewNode = (Node*)malloc(sizeof(Node));
	if (NULL == pNewNode)
	{
		return;
	}

	pNewNode->nData = nData;
	pNewNode->pNext = *pList;
	
	(*pList) = pNewNode;
}

void Pop( LinkList* pList, int nData )
{
	if (NULL == *pList)
	{
		return;
	}

	LinkList list = *pList;


	if (list->nData == nData)
	{
		*pList = list->pNext;
		free(list);
		return;
	}

	while(list)
	{
		if (list->pNext->nData == nData)
		{
			list->pNext = list->pNext->pNext;
			free(list->pNext);
			break;
		}
		list = list->pNext;
	}
}

void Show( LinkList list )
{
	if (NULL == list)
	{
		return;
	}

	printf("List:");

	while (NULL != list)
	{
		printf("%d, ", list->nData);
		list = list->pNext;
	}

	printf("\n");
}	

void Reverse( LinkList list )
{
	if (NULL == list)
	{
		return;
	}

	Node *pCur = list;
	Node *pNext = list->pNext;
	Node *pTmp;

	while(pCur && pNext)
	{
		pTmp = pNext->pNext;
		pNext->pNext = pCur;

		pCur = pCur->pNext;
		pNext = pNext->pNext;
	}
}
